var s_index_id,s_org_id,s_start;

$(document).ready(function(){ 
	loadGrid(); 
	$('#tree1').tree({
		animate:true,
		url:"index/getTree.action"
		//url:"index/getTree.do"
	});
});

function loadGrid(){
	$('#cxdm').datagrid({
		width: 'auto',  
		height:300,   
		idField: 'org_id',
		striped: true,  
		singleSelect : true, 
		rownumbers: true,
		toolbar: "#toolbar",
		onDblClickCell:function(index,field,value){
			var row = $('#cxdm').datagrid('getSelected');
			var org_id="";
			if (row){
				org_id = row.id;
			}
			
			$.ajax({
				url: "index/toedit.do?index_id="+field+"&year="+$('#start').val()+"&org_id="+org_id,
				type: "get",
				dataType: "json",
				cache: true,
				success: function(result) {
					$('#dlg').dialog('open').dialog('setTitle','指标数据维护');
					$('#fm').form('load',result);
					
				},
				error: function(result, status) {
					if (status == 'error') {
						alert("系统发生错误！请刷新页面后重试！");
					}
				}
			});
		}
	});
}

$(document).ready(function(){  
	$('#start').val(new Date().getYear()+0);
	$('#qy').combotree('setValue', '50');
});

function searchInfo(){
	 var node = $('#tree1').tree('getSelected');
	 if(node == null){
		 alert("选择指标");
		 return false;
	 }
	 s_index_id = node.id;
	 $('#s_index_id').val(s_index_id);
	 $.ajax({
			url: "index/getSub.do?id="+s_index_id,
			type: "get",
			dataType: "json",
			cache: true,
			beforeSend: function(result) {
				
			},
			success: function(result) {
				var cols = result.json;
				var options = {
						width: "auto",
						height: "auto"
				};
				options.columns = eval(cols);
				$('#cxdm').datagrid(options);
				getDatas();
			},
			error: function(result, status) {
				if (status == 'error') {
					alert("系统发生错误！请刷新页面后重试！");
				}
			}
		});
}

function getDatas(){
	if($('#start').val()==''){
		alert('时间为空');
		return false;
	}
	s_org_id=$('#qy').combotree('getValue');
	s_start=$('#start').val();
	$('#s_org_id').val(s_org_id);
	$('#s_start').val(s_start);
	$.ajax({
		url: "org/getData.do?org_id="+s_org_id+"&start="+s_start,
		type: "get",
		dataType: "json",
		cache: true,
		beforeSend: function(result) {
			
		},
		success: function(result) {
			//var cols = result.json;
			//alert(cols);
			$('#cxdm').datagrid('loadData',result);
		},
		error: function(result, status) {
			if (status == 'error') {
				alert("系统发生错误！请刷新页面后重试！");
			}
		}
	});
}

function exportExcel(){
	$("form#form1").submit();
}
function editIndexDate(){
	$('#fm').form('submit',{
		url: "index/editdata.do",
		success: function(result){ 
			$('#dlg').dialog('close'); 
			getDatas();
		}
	});
}